package com.itjason.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itjason.po.Comments;
import com.itjason.service.CommentsService;
import com.itjason.mapper.CommentsMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author dengxiang
* @description 针对表【comments】的数据库操作Service实现
* @createDate 2024-06-03 21:03:04
*/
@Service
public class CommentsServiceImpl extends ServiceImpl<CommentsMapper, Comments>
    implements CommentsService{

    @Resource
    private CommentsMapper commentsMapper;

    @Override
    public int addComment(Comments comments) {
        return commentsMapper.insert(comments);
    }

    @Override
    public int deleteComment(Integer userId, Integer dynamicId, Integer commentId) {

        if(commentId == null){
            return commentsMapper.deleteComments(userId,dynamicId);
        }

        return commentsMapper.deleteComment(userId,dynamicId,commentId);
    }

    @Override
    public List<Comments> selectCommentsByDynamicId(Integer dynamicId) {
        LambdaQueryWrapper<Comments> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(Comments::getDynamicId,dynamicId);
        return commentsMapper.selectList(queryWrapper);
    }
}




